<%@ page import="hyl.dao.UserDao" %>
<%@ page import="hyl.dao.UserDaoImpl" %>
<%@ page import="hyl.entity.User" %><%--
  Created by IntelliJ IDEA.
  User: Elle
  Date: 2022/6/11
  Time: 10:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    //处理页面

    //1、获取请求的数据
    String userId = request.getParameter("userId"); //jsp页面中的表单数据
    String passWord  = request.getParameter("passWord"); //jsp页面中的表单数据
    String checkbox = request.getParameter("checkbox"); //jsp页面中的表单数据

    //2、操作
    UserDao userDao = new UserDaoImpl();
    User user = userDao.login(userId); //传参==》jsp页面中的表单数据
    if(user == null){
    	//错误
        out.print("<script>alert('您输入的用户名错误');location.href='../login.jsp';</script>");
    }else  if(!user.getPassword().equals(passWord)){
        //错误
        out.print("<script>alert('您输入的密码错误');location.href='../login.jsp';</script>");
    }else{
    	//判断是否“记住我”
        if(checkbox!=null){
        	//将登入用户的信息，写入到Cookie中
            Cookie userCookie = new Cookie("loginUserid",userId);
            Cookie pwdCookie = new Cookie("loginPwd",passWord);
            //使用response
            response.addCookie(userCookie);
            response.addCookie(pwdCookie);
        }
        session.setAttribute("loginuser", user);
        //3、页面跳转
        response.sendRedirect("../index.jsp");
        //request.getRequestDispatcher("login.jsp").forward(request, response);
    }

%>
